package cn.kgc.spring.factory;

import org.springframework.beans.factory.FactoryBean;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * @author: mosin
 * @version: v1.0  2022/10/12
 * 自定义工厂对象获取复杂类型的对象
 * 实例工厂
 * 1.定义一个普通类
 * 2.再类中定义一个普通方法 返回值是想要获取的bean类型
 * 3.声明实例工厂在spring容器中
 * <bean id="connectionFactoryBean2" class="cn.kgc.spring.factory.ConnectionFactoryBean2"></bean>
 * <bean id="conn" factory-bean="connectionFactoryBean2" factory-method="getConnection"></bean>
 *
 */
public class ConnectionFactoryBean2  {

    public Connection getConnection() throws Exception {
        Class.forName("com.mysql.jdbc.Driver");
        Connection connection = DriverManager.getConnection("jdbc:mysql:///java2216", "root", "root");
        return connection;
    }

}
